<!DOCTYPE HTML PUBLIC "HTML 4.01 Transitional">
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>utils.lsp</title>

<link rel="stylesheet" type="text/css" href="newlispdoc.css" />
</head>

<body style="margin: 20px;" text="#111111" bgcolor="#FFFFFF" 
			link="#376590" vlink="#551A8B" alink="#ffAA28">
<blockquote>
<center><h1>utils.lsp</h1></center>
<p><a href="index.html">Module index</a></p><br/><h2>Module:&nbsp;utils.lsp</h2><b>Author: </b>Greg Slepak <greg at taoeffect.com><br/>
 <p>This file not only provides the functions documented below, but
 it also plays a role in globally overriding certain functions in the MAIN context.</p>
 <p>The overridden functions include: <tt>load</tt>, <tt>print</tt>, and <tt>println</tt>.</p>
 <p><tt>load</tt> is overwritten to load a file only once, while <tt>print</tt> and <tt>println</tt>
 are overwritten to send their output the the <tt>Dragonfly:STDOUT</tt> buffer, allowing
 Dragonfly to ensure pages are displayed properly.</p>

<br/><br/><center>- &sect; -</center><br/>
<a name="_add-to-load-path"></a><h3><font color=#CC0000>add-to-load-path</font></h3>
<b>syntax: (<font color=#CC0000>add-to-load-path</font> <em>str-path-1</em> <em>str-path-2</em> ...)</b><br/>
 <p>Dragonfly overrides the built-in function <tt>load</tt> so that files
 are loaded only once. In addition it supports the concept of "load paths"
 which can be added using this function. This means that you no longer need
 to modify third-party code that contains <tt>load</tt> calls to files located in
 different locations. Simply add a new load path instead.</p>
 <b>example:</b>
 <pre> ; the old way
 (load "MyClass.lsp") ;=> ERROR! MyClass.lsp doesn't exist here!
 ; we must rewrite the file to point to the new location of MyClass.lsp:
 (load "../../myfolder/MyClass.lsp")
 ; -------------------------------
 ; New way, using add-to-load-path
 ; -------------------------------
 (add-to-load-path "../../myfolder")
 ; no need to update any source files, it just works.</pre>
 <b>warning:</b> Use this function sparingly as name-conflicts could
 result in the wrong file being loaded!

<br/><br/><center>- &sect; -</center><br/>
<a name="_file-ext"></a><h3><font color=#CC0000>file-ext</font></h3>
<b>syntax: (<font color=#CC0000>file-ext</font> <em>str-path</em>)</b><br/>
 <p>Returns the file extension of the file in <em>str-path</em></p>
 <pre> (file-ext "")
 ;=> ""
 (file-ext "asdf")
 ;=> ""
 (file-ext "asdf.")
 ;=> ""
 (file-ext "asdf.jpg")
 ;=> "jpg"</pre>

<br/><br/><center>- &sect; -</center><br/>
<a name="_del-ext"></a><h3><font color=#CC0000>del-ext</font></h3>
<b>syntax: (<font color=#CC0000>del-ext</font> <em>str-path</em>)</b><br/>
 <p>Returns the <em>str-path</em> without the file extension removed.</p>
 <pre> (del-ext "")
 ;=> ""
 (del-ext "asdf")
 ;=> "asdf"
 (del-ext "asdf.")
 ;=> "asdf."
 (del-ext "asdf.jpg")
 ;=> "asdf"</pre>

<br/><br/><center>- &sect; -</center><br/>
<a name="_basename"></a><h3><font color=#CC0000>basename</font></h3>
<b>syntax: (<font color=#CC0000>basename</font> <em>str-path</em>)</b><br/>
 <p>Returns the filename component of <em>str-path</em>.</p>
 <pre> (basename "")
 ;=> ""
 (basename "/")
 ;=> ""
 (basename "asdf")
 ;=> "asdf"
 (basename "/foo/bar")
 ;=> "bar"
 (basename "/foo/bar/")
 ;=> "bar"</pre>

<br/><br/><center>- &sect; -</center><br/>
<a name="_dirname"></a><h3><font color=#CC0000>dirname</font></h3>
<b>syntax: (<font color=#CC0000>dirname</font> <em>str-path</em>)</b><br/>
 <p>Returns the directory path component of <em>str-path</em>.</p>
 <pre> (dirname "")
 ;=> ""
 (dirname "/")
 ;=> "/"
 (dirname "asdf")
 ;=> "."
 (dirname "/asdf/")
 ;=> "/"
 (dirname "asdf/foo")
 ;=> "asdf"</pre>

<br/><br/><center>- &sect; -</center><br/>
<a name="_regex-captcha"></a><h3><font color=#CC0000>regex-captcha</font></h3>
<b>syntax: (<font color=#CC0000>regex-captcha</font> <em>str-regex</em> <em>str</em> [<em>int-options</em>] [<em>int-captcha</em>])</b><br/>
<b>parameter: </b><em>int-options</em> - options to regex, defaults to 0.<br/>
<b>parameter: </b><em>int-captch</em> - which of the regex group captures to return, defaults to 1.<br/>
 <p>Returns the captured text, or nil if it couldn't be captured.<br/>This is a global function.</p>
 <b>example:</b>
 <pre> (regex-captcha {^(foo|bar).*} "foobaz") => "foo"
 (regex-captcha {^(foo|bar).*} "bazfoo") => nil</pre>
<br/><br/>
<br/><br/><center>- &sect; -</center><br/>
<a name="_load-files-in-dir"></a><h3><font color=#CC0000>load-files-in-dir</font></h3>
<b>syntax: (<font color=#CC0000>load-files-in-dir</font> <em>str-dir</em> <em>regex-match</em>)</b><br/>
 <p>Loads all the files in <em>str-dir</em> matching <em>regex-match</em>. Does not
 traverse subdirectories.<br/>This is a global function.</p>
<br/><br/>
<br/><br/><center>- &sect; -</center><br/>
<a name="_wrap-func"></a><h3><font color=#CC0000>wrap-func</font></h3>
<b>syntax: (<font color=#CC0000>wrap-func</font> <em>func</em> <em>lambda</em>)</b><br/>
 <p>Replaces <em>func</em> with <em>lambda</em>. Inside of <em>lambda</em> use <tt>wrapped-func</tt> to refer
 to the original function. This can be very handy for "aspect oriented programming".</p>
 <b>example:</b>
 <pre> (wrap-func db:execute-update
     (fn () (unless (apply wrapped-func $args)
         (throw-error (string "execute-update failed: " $args)))))</pre>

<br/><br/><center>- &sect; -</center><br/>
<a name="_SET_DF_SELF"></a><h3><font color=#CC0000>SET_DF_SELF</font></h3>
<b>syntax: (<font color=#CC0000>SET_DF_SELF</font> <em>str-filepath</em>)</b><br/>
<b>parameter: </b><em>str-filepath</em> - The path to the file being served, or the primary file responsible for handling this route.<br/>
 <p>Routes should call this global function with the path to the file that's being displayed
 or the file that's principly in charge of handling this route. This function will then
 set the global variables <tt>DF_SELF</tt> and <tt>DF_SELF_DIR</tt> to point to that file and its
 parent directory, respectively.</p>
 <p>The default routes <tt>Route.Static</tt> and <tt>Route.Resource</tt> call this function first thing
 in their <tt>Route:run</tt> methods, prior to loading the files. This is the recommended way of
 calling this function.</p>
<br/><br/><center>- &sect; -</center><br/>
<a name="_define-smacro"></a><h3><font color=#CC0000>define-smacro</font></h3>
<b>syntax: (<font color=#CC0000>define-smacro</font>)</b><br/>
 <p>Defines a "safe macro", free of variable capture issues. Note though
 that it does this by placing the macro in its own context, so be careful
 when choosing its name!</p>
<br/><br/><center>- &sect; -</center><br/>
<a name="_NEWLISP64"></a><h3><font color=#CC0000>NEWLISP64</font></h3>
<b>syntax: NEWLISP64</b><br/>
 <p>A constant that is <tt>true</tt> if we're running the 64-bit version of newLISP.</p>
<br/><br/><center>- &sect; -</center><br/>
<a name="_get-ptr"></a><h3><font color=#CC0000>get-ptr</font></h3>
<b>syntax: (<font color=#CC0000>get-ptr</font> <em>symbol</em>)</b><br/>
 <p>Alias for <tt>get-long</tt> on 64-bit systems, and <tt>get-int</tt> on 32-bit systems.</p>
<br/><br/><center>- &sect; -</center><br/>
<a name="_throw-not-implemented"></a><h3><font color=#CC0000>throw-not-implemented</font></h3>
<b>syntax: (<font color=#CC0000>throw-not-implemented</font>)</b><br/>
 <p>Used to indicate that an ObjNL method *must* be overwritten.</p>
<br/><br/><center>- &sect; -</center><br/>
<a name="_<-"></a><h3><font color=#CC0000><-</font></h3>
<b>syntax: (<font color=#CC0000><-</font> <em>key</em> <em>assoc-list</em>)</b><br/>
 <p>An alias for <tt>lookup</tt></p>


<br/><br/><center>- &part; -</center><br/>
<center><font face='Arial' size='-2' color='#444444'>
generated with <a href="http://newlisp.org">newLISP</a>&nbsp;
and <a href="http://newlisp.org/newLISPdoc.html">newLISPdoc</a>
</font></center>
</blockquote>
</body>
</html>
